package com.ruoyi.web.controller.wxopen;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.wechat.open.domain.WxConfig;
import com.ruoyi.wechat.open.service.IWxConfigService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 系统公众号Controller
 * 
 * @author ruoyi
 * @date 2020-11-28
 */
@RestController
@RequestMapping("/wxconfig")
public class WxConfigController extends BaseController
{
    @Autowired
    private IWxConfigService wxConfigService;

    @Autowired
    private TokenService tokenService;
    /**
     * 查询系统公众号列表
     */
    @PreAuthorize("@ss.hasPermi('wxmp:wxconfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(WxConfig wxConfig)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        SysUser user = loginUser.getUser();
        startPage();
        List<WxConfig> list = wxConfigService.selectWxConfigListByUser(user,wxConfig);
        return getDataTable(list);
    }

    /**
     * 导出系统公众号列表
     */
    @PreAuthorize("@ss.hasPermi('wxmp:wxconfig:export')")
    @Log(title = "系统公众号", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WxConfig wxConfig)
    {
        List<WxConfig> list = wxConfigService.selectWxConfigList(wxConfig);
        ExcelUtil<WxConfig> util = new ExcelUtil<WxConfig>(WxConfig.class);
        return util.exportExcel(list, "jwid");
    }

    /**
     * 获取系统公众号详细信息
     */
    @PreAuthorize("@ss.hasPermi('wxmp:wxconfig:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(wxConfigService.selectWxConfigById(id));
    }

    /**
     * 新增系统公众号
     */
    @PreAuthorize("@ss.hasPermi('wxmp:wxconfig:add')")
    @Log(title = "系统公众号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxConfig wxConfig)
    {
        return toAjax(wxConfigService.insertWxConfig(wxConfig));
    }

    /**
     * 修改系统公众号
     */
    @PreAuthorize("@ss.hasPermi('wxmp:wxconfig:edit')")
    @Log(title = "系统公众号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxConfig WxConfig)
    {
        return toAjax(wxConfigService.updateWxConfig(WxConfig));
    }

    /**
     * 删除系统公众号
     */
    @PreAuthorize("@ss.hasPermi('wxmp:wxconfig:remove')")
    @Log(title = "系统公众号", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(wxConfigService.deleteWxConfigByIds(ids));
    }
}
